Micron Document
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| SparkN0de-git | SparkN0de |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Commit d661ba053183dfd1c9d3350bc2a8a7d1a70a2ecf


Parents : a1b1aea
Author : Mark Qvist <bc7291552be7a58f361522990465165c>
Date : 2026-05-22T11:48:36+02:00

Run UI-side message cleaning with hub lock

Changes

2 files changed, 20 insertions(+), 17 deletions(-)


Diff

diff --git a/nomadnet/RRC.py b/nomadnet/RRC.py
index c9c26a3..04e212e 100644
--- a/nomadnet/RRC.py
+++ b/nomadnet/RRC.py
@@ -815,9 +815,11 @@ class RRCHub:
self._append_history(target_room, msg)
self._clean_history()
- def get_messages(self, room):
- with self._lock:
- buf = list(self.messages.get(room, []))
+ def get_messages(self, room, take_lock=True):
+ if take_lock:
+ with self._lock: buf = list(self.messages.get(room, []))
+ else: buf = list(self.messages.get(room, []))
+
return buf
def _on_packet(self, data):

diff --git a/nomadnet/ui/textui/Channels.py b/nomadnet/ui/textui/Channels.py
index 9ea54b0..2bdb882 100644
--- a/nomadnet/ui/textui/Channels.py
+++ b/nomadnet/ui/textui/Channels.py
@@ -773,20 +773,21 @@ class RoomWidget(urwid.WidgetWrap):
if self.hub.clean_last_removed > self.last_history_clean:
try:
- hub_msgs = self.hub.get_messages(self.room) if (self.hub is not None and self.room is not None) else []
- self.last_history_clean = time.time()
- c = self.messagelist.body_len()
- old = set()
- for i in range(0, c):
- msg = None
- w = self.messagelist.get_item(i)
- if hasattr(w, "_original_widget"): o = w._original_widget
- else: o = None
- if hasattr(o, "msg"): msg = o.msg
- elif hasattr(w, "msg"): msg = w.msg
- if msg and not msg in hub_msgs: old.add(i)
-
- for i in reversed(list(old)): self.messagelist.delete_position(i)
+ with self.hub._lock:
+ hub_msgs = self.hub.get_messages(self.room, take_lock=False) if (self.hub is not None and self.room is not None) else []
+ self.last_history_clean = time.time()
+ c = self.messagelist.body_len()
+ old = set()
+ for i in range(0, c):
+ msg = None
+ w = self.messagelist.get_item(i)
+ if hasattr(w, "_original_widget"): o = w._original_widget
+ else: o = None
+ if hasattr(o, "msg"): msg = o.msg
+ elif hasattr(w, "msg"): msg = w.msg
+ if msg and not msg in hub_msgs: old.add(i)
+
+ for i in reversed(list(old)): self.messagelist.delete_position(i)
except Exception as e:
RNS.log("Error while cleaning room history", RNS.LOG_ERROR)


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────